<!DOCTYPE html>
<html lang="en">
<head>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">
  <meta charset="UTF-8">
  <meta name="Author" content="haley">
  <meta name="Keywords" content="前端最常用的UI插件">
  <meta name="Description" content="最常用的UI插件">
  <script crossorigin="anonymous" integrity="sha384-6ePHh72Rl3hKio4HiJ841psfsRJveeS+aLoaEf3BWfS+gTF0XdAqku2ka8VddikM" src="https://lib.baomitu.com/jquery/1.11.3/jquery.min.js"></script>
  <title></title>
</head>
<body>
<div style="height: 400px;border:1px solid #F00;"></div>
  <h2>
    <span class="num1">33</span>
    <span class="num2">113</span>
    <span class="num3">168</span>
    <span class="num4">98</span>
  </h2>
  <script>
    /* 主控程序 */
    var w = $(window).width();//当前显示器宽度
    var SCREENlLIMIT=767;
    <!--奔跑数字-->
    var numbers=[33,113,168,98];
    var cons=[
      {"name":$('.num1'),"n":numbers[0]},
      {"name":$('.num2'),"n":numbers[1]},
      {"name":$('.num3'),"n":numbers[2]},
      {"name":$('.num4'),"n":numbers[3]}
    ];
    var timer=null;
    var seconds=3000;//加载时长
    $.fn.extend({
      'runSecond': function () {
        var elem = $(this);
        var h = elem.html()/1;
        var a = 0;
        timer = setInterval(function () {
          if (a <= h) {
            elem.html(a++);
          } else {
//                    clearInterval(timer);
            timer = null;
          }
        }, seconds / h);
      }
    });
    //滚动条滚动到某个位置时开始跑秒
    $(function () {
      var isScroll= 1;
      //min & max
      var limits={
        pc:{'min':100,'max':300},
        wap:{'min':150,'max':250}
      };

      //滚动条滚动到某个位置时开始跑秒
      $(window).scroll(function(){
        function scrollT(){
          if($('body').scrollTop()){
            return $('body').scrollTop();
          }else if($('html').scrollTop()){
            return $('html').scrollTop();
          }else{
            $('document').scrollTop()
          }
        }
        function run(){
          $('.num1').runSecond();
          $('.num2').runSecond();
          $('.num3').runSecond();
          $('.num4').runSecond();
        }
        var scrollTop=scrollT();
        console.log(scrollTop);
        if(w>SCREENlLIMIT){
          if(scrollTop>limits.pc.max&&isScroll%2){
            isScroll++;
            run();
          }
          if(scrollTop<limits.pc.min){
            isScroll=1;
          }
        }else{
          if(scrollTop>limits.wap.max&&isScroll%2){
            isScroll++;
            run();
          }
          if(scrollTop<limits.wap.min){
            isScroll=1;
          }
        }
      });

    });
  </script>
<div style="height: 1200px"></div>
</body>
</html>
